<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>《统计学习方法》第 6 章“逻辑回归”学习笔记 | 算法不好玩</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/book/logo.png">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.min.css">
    <meta name="description" content="">
    
    <link rel="preload" href="/book/assets/css/0.styles.e159a327.css" as="style"><link rel="preload" href="/book/assets/js/app.a4355b0d.js" as="script"><link rel="preload" href="/book/assets/js/2.ba785ee6.js" as="script"><link rel="preload" href="/book/assets/js/44.386d9aea.js" as="script"><link rel="prefetch" href="/book/assets/js/10.b6950be1.js"><link rel="prefetch" href="/book/assets/js/11.f4ee7d6e.js"><link rel="prefetch" href="/book/assets/js/12.50fe1ace.js"><link rel="prefetch" href="/book/assets/js/13.42356fcc.js"><link rel="prefetch" href="/book/assets/js/14.e740c742.js"><link rel="prefetch" href="/book/assets/js/15.05c628f7.js"><link rel="prefetch" href="/book/assets/js/16.bd9bc9d5.js"><link rel="prefetch" href="/book/assets/js/17.e120b4fc.js"><link rel="prefetch" href="/book/assets/js/18.398213f8.js"><link rel="prefetch" href="/book/assets/js/19.e29ad0b2.js"><link rel="prefetch" href="/book/assets/js/20.14e30c1c.js"><link rel="prefetch" href="/book/assets/js/21.4f05f6c9.js"><link rel="prefetch" href="/book/assets/js/22.98fbf199.js"><link rel="prefetch" href="/book/assets/js/23.285387f4.js"><link rel="prefetch" href="/book/assets/js/24.852addbe.js"><link rel="prefetch" href="/book/assets/js/25.d30ade13.js"><link rel="prefetch" href="/book/assets/js/26.23dfa040.js"><link rel="prefetch" href="/book/assets/js/27.b6eae7df.js"><link rel="prefetch" href="/book/assets/js/28.97878b08.js"><link rel="prefetch" href="/book/assets/js/29.7217a3d0.js"><link rel="prefetch" href="/book/assets/js/3.f0c15194.js"><link rel="prefetch" href="/book/assets/js/30.0ced5a5a.js"><link rel="prefetch" href="/book/assets/js/31.8f432033.js"><link rel="prefetch" href="/book/assets/js/32.aac9aa62.js"><link rel="prefetch" href="/book/assets/js/33.db835477.js"><link rel="prefetch" href="/book/assets/js/34.a1a59c2a.js"><link rel="prefetch" href="/book/assets/js/35.ed2ef96b.js"><link rel="prefetch" href="/book/assets/js/36.48099c55.js"><link rel="prefetch" href="/book/assets/js/37.32827612.js"><link rel="prefetch" href="/book/assets/js/38.58abec0e.js"><link rel="prefetch" href="/book/assets/js/39.f6eb3874.js"><link rel="prefetch" href="/book/assets/js/4.13ea3b32.js"><link rel="prefetch" href="/book/assets/js/40.80523ed8.js"><link rel="prefetch" href="/book/assets/js/41.f7b72b7a.js"><link rel="prefetch" href="/book/assets/js/42.44e40de9.js"><link rel="prefetch" href="/book/assets/js/43.065f077f.js"><link rel="prefetch" href="/book/assets/js/45.d8a88f16.js"><link rel="prefetch" href="/book/assets/js/46.33bc2083.js"><link rel="prefetch" href="/book/assets/js/47.e7767237.js"><link rel="prefetch" href="/book/assets/js/48.9bb76138.js"><link rel="prefetch" href="/book/assets/js/49.c2ca5c29.js"><link rel="prefetch" href="/book/assets/js/5.32eda204.js"><link rel="prefetch" href="/book/assets/js/50.1242fe24.js"><link rel="prefetch" href="/book/assets/js/51.e8f8117d.js"><link rel="prefetch" href="/book/assets/js/52.eae5648f.js"><link rel="prefetch" href="/book/assets/js/53.39876d83.js"><link rel="prefetch" href="/book/assets/js/6.1c662163.js"><link rel="prefetch" href="/book/assets/js/7.29470445.js"><link rel="prefetch" href="/book/assets/js/8.814b737f.js"><link rel="prefetch" href="/book/assets/js/9.d4211262.js">
    <link rel="stylesheet" href="/book/assets/css/0.styles.e159a327.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/book/" class="home-link router-link-active"><!----> <span class="site-name">算法不好玩</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/book/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/book/guide/" class="nav-link">
  关于我
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="基础算法与数据结构" class="dropdown-title"><span class="title">基础算法与数据结构</span> <span class="arrow down"></span></button> <button type="button" aria-label="基础算法与数据结构" class="mobile-dropdown-title"><span class="title">基础算法与数据结构</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          排序算法
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/book/algs/01-binary-search/" class="nav-link">
  第 1 章 二分查找
</a></li><li class="dropdown-subitem"><a href="/book/algs/recursion/" class="nav-link">
  第 2 章 递归
</a></li></ul></li><li class="dropdown-item"><h4>
          数组里的算法
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/book/algs/01-binary-search/" class="nav-link">
  第 4 章 滑动窗口
</a></li><li class="dropdown-subitem"><a href="/book/algs/02-basic-sorting/" class="nav-link">
  第 5 章 双指针
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="威威道来" class="dropdown-title"><span class="title">威威道来</span> <span class="arrow down"></span></button> <button type="button" aria-label="威威道来" class="mobile-dropdown-title"><span class="title">威威道来</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/book/talk-show/2021-04/" class="nav-link">
  2021 年 4 月
</a></li></ul></div></div><div class="nav-item"><a href="https://leetcode-cn.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  力扣
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://gitee.com/liweiwei1419/book/pages" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Gitee 部署页面
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/book/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/book/guide/" class="nav-link">
  关于我
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="基础算法与数据结构" class="dropdown-title"><span class="title">基础算法与数据结构</span> <span class="arrow down"></span></button> <button type="button" aria-label="基础算法与数据结构" class="mobile-dropdown-title"><span class="title">基础算法与数据结构</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          排序算法
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/book/algs/01-binary-search/" class="nav-link">
  第 1 章 二分查找
</a></li><li class="dropdown-subitem"><a href="/book/algs/recursion/" class="nav-link">
  第 2 章 递归
</a></li></ul></li><li class="dropdown-item"><h4>
          数组里的算法
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/book/algs/01-binary-search/" class="nav-link">
  第 4 章 滑动窗口
</a></li><li class="dropdown-subitem"><a href="/book/algs/02-basic-sorting/" class="nav-link">
  第 5 章 双指针
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="威威道来" class="dropdown-title"><span class="title">威威道来</span> <span class="arrow down"></span></button> <button type="button" aria-label="威威道来" class="mobile-dropdown-title"><span class="title">威威道来</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/book/talk-show/2021-04/" class="nav-link">
  2021 年 4 月
</a></li></ul></div></div><div class="nav-item"><a href="https://leetcode-cn.com/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  力扣
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://gitee.com/liweiwei1419/book/pages" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Gitee 部署页面
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <!----></nav>  <!----> </aside> <main class="page"> <div class="theme-default-content content__default"><div class="custom-block tip"><p class="custom-block-title">TIP</p> <p>本文介绍了逻辑回归模型。</p></div> <h1 id="《统计学习方法》第-6-章-逻辑回归-学习笔记"><a href="#《统计学习方法》第-6-章-逻辑回归-学习笔记" class="header-anchor">#</a> 《统计学习方法》第 6 章“逻辑回归”学习笔记</h1> <h3 id="用于分类"><a href="#用于分类" class="header-anchor">#</a> 用于分类</h3> <p>逻辑回归是一个分类模型，“逻辑”是 Logistic 的音译。之所以叫回归，是因为它<strong>实际上预测的是概率</strong>，即拟合概率，只是“临门一脚”，选择概率最大的类作为预测的分类结果，逻辑回归本质上是一个回归问题。</p> <p>逻辑回归解决分类问题，且只用于二分类，在本章节的最后，我们沿用二分类的思路可以解决多分类问题。</p> <p>Logistic 回归是一种思想简单，且应用广泛的分类方法。相对于深度学习而言，深度学习等复杂的机器学习算法，对数据的要求很高，朴素简单的 Logistic 往往有时能达到很好的效果。</p> <p>在线性回归中，我们找到一组参数 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="3B8"></mjx-c></mjx-mi></mjx-math></mjx-container> ，使得 $y = \theta \cdot x_b $ 去拟合数据点，这里的 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="y"></mjx-c></mjx-mi><mjx-mo space="4" class="mjx-n"><mjx-c c="2208"></mjx-c></mjx-mo><mjx-mo space="4" class="mjx-n"><mjx-c c="("></mjx-c></mjx-mo><mjx-mo class="mjx-n"><mjx-c c="2212"></mjx-c></mjx-mo><mjx-mi class="mjx-n"><mjx-c c="221E"></mjx-c></mjx-mi><mjx-mo class="mjx-n"><mjx-c c=","></mjx-c></mjx-mo><mjx-mo space="2" class="mjx-n"><mjx-c c="+"></mjx-c></mjx-mo><mjx-mi class="mjx-n"><mjx-c c="221E"></mjx-c></mjx-mi><mjx-mo class="mjx-n"><mjx-c c=")"></mjx-c></mjx-mo></mjx-math></mjx-container>。</p> <p>我们知道，<mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mo class="mjx-n"><mjx-c c="("></mjx-c></mjx-mo><mjx-mo class="mjx-n"><mjx-c c="2212"></mjx-c></mjx-mo><mjx-mi class="mjx-n"><mjx-c c="221E"></mjx-c></mjx-mi><mjx-mo class="mjx-n"><mjx-c c=","></mjx-c></mjx-mo><mjx-mo space="2" class="mjx-n"><mjx-c c="+"></mjx-c></mjx-mo><mjx-mi class="mjx-n"><mjx-c c="221E"></mjx-c></mjx-mi><mjx-mo class="mjx-n"><mjx-c c=")"></mjx-c></mjx-mo></mjx-math></mjx-container> 有两个极端，对于二分类问题，就使用这两个极端来做分类，越极端越肯定，即越趋于无穷，概率值越趋近于 0 或 1，这里 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="y"></mjx-c></mjx-mi><mjx-mo space="4" class="mjx-n"><mjx-c c="="></mjx-c></mjx-mo><mjx-mn space="4" class="mjx-n"><mjx-c c="0"></mjx-c></mjx-mn></mjx-math></mjx-container> 就是这两类的分类边界。下面看一个例子。</p> <p>对于一个二分类 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-TeXAtom><mjx-mi class="mjx-i"><mjx-c c="A"></mjx-c></mjx-mi><mjx-mo class="mjx-n"><mjx-c c=","></mjx-c></mjx-mo><mjx-mi space="2" class="mjx-i"><mjx-c c="B"></mjx-c></mjx-mi></mjx-TeXAtom></mjx-math></mjx-container> 问题，如果我们通过逻辑回归计算出来的参数 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="3B8"></mjx-c></mjx-mi></mjx-math></mjx-container>，使得 $y = \theta \cdot x_b $ 的值大于 0，则判定属于 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="A"></mjx-c></mjx-mi></mjx-math></mjx-container> 类，如果计算出来 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="y"></mjx-c></mjx-mi></mjx-math></mjx-container> 的值小于 0，则判定属于 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="B"></mjx-c></mjx-mi></mjx-math></mjx-container> 类。如果 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="y"></mjx-c></mjx-mi></mjx-math></mjx-container> 的值越大，则我们越肯定该预测点属于 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="A"></mjx-c></mjx-mi></mjx-math></mjx-container> 类，如果 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="y"></mjx-c></mjx-mi></mjx-math></mjx-container> 的值越小，则我们越肯定该预测点属于 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="B"></mjx-c></mjx-mi></mjx-math></mjx-container> 类。</p> <p><mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="3B8"></mjx-c></mjx-mi><mjx-mo space="3" class="mjx-n"><mjx-c c="22C5"></mjx-c></mjx-mo><mjx-msub space="3"><mjx-mi noIC="true" class="mjx-i"><mjx-c c="x"></mjx-c></mjx-mi><mjx-script style="vertical-align:-0.15em;"><mjx-mi size="s" class="mjx-i"><mjx-c c="b"></mjx-c></mjx-mi></mjx-script></mjx-msub><mjx-mo space="4" class="mjx-n"><mjx-c c="="></mjx-c></mjx-mo><mjx-mn space="4" class="mjx-n"><mjx-c c="0"></mjx-c></mjx-mn></mjx-math></mjx-container> 是一个超平面，在三维空间中，就是一个平面，在二维空间中，就是一条直线，根据点到超平面的距离公式：
<mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mfrac><mjx-frac><mjx-num><mjx-nstrut></mjx-nstrut><mjx-mrow size="s"><mjx-mpadded><mjx-block style="margin:0.896em 0 0.313em;"><mjx-mrow></mjx-mrow></mjx-block></mjx-mpadded><mjx-mstyle style="font-size:141.4%;"><mjx-TeXAtom><mjx-mi class="mjx-i"><mjx-c c="3B8"></mjx-c></mjx-mi><mjx-mo space="3" class="mjx-n"><mjx-c c="22C5"></mjx-c></mjx-mo><mjx-msub space="3"><mjx-mi noIC="true" class="mjx-i"><mjx-c c="x"></mjx-c></mjx-mi><mjx-script style="vertical-align:-0.15em;"><mjx-mi size="s" class="mjx-i"><mjx-c c="b"></mjx-c></mjx-mi></mjx-script></mjx-msub></mjx-TeXAtom></mjx-mstyle></mjx-mrow></mjx-num><mjx-dbox><mjx-dtable><mjx-line></mjx-line><mjx-row><mjx-den><mjx-dstrut></mjx-dstrut><mjx-mrow size="s"><mjx-mpadded><mjx-block style="margin:0.896em 0 0.313em;"><mjx-mrow></mjx-mrow></mjx-block></mjx-mpadded><mjx-mstyle style="font-size:141.4%;"><mjx-TeXAtom><mjx-mo class="mjx-n"><mjx-c c="|"></mjx-c></mjx-mo><mjx-mo class="mjx-n"><mjx-c c="|"></mjx-c></mjx-mo><mjx-mi class="mjx-i"><mjx-c c="3B8"></mjx-c></mjx-mi><mjx-mo class="mjx-n"><mjx-c c="|"></mjx-c></mjx-mo><mjx-msup><mjx-mo class="mjx-n"><mjx-c c="|"></mjx-c></mjx-mo><mjx-script style="vertical-align:0.363em;"><mjx-mn size="s" class="mjx-n"><mjx-c c="2"></mjx-c></mjx-mn></mjx-script></mjx-msup></mjx-TeXAtom></mjx-mstyle></mjx-mrow></mjx-den></mjx-row></mjx-dtable></mjx-dbox></mjx-frac></mjx-mfrac></mjx-math></mjx-container>，$\theta \cdot x_b $ 的绝对值越大，则表明预测点离这条直线越远，则我们越敢肯定，预测点属于其中一个类别。</p> <ul><li>$\theta \cdot x_b $ 的符号，决定了预测点的类别，在逻辑回归中，我们定义类别为“1”和“0”。
说明：我们完全可以将类别定义为“A”、“B”，或者 1、-1（在 SVM 算法中，就是这么定义的）。我们的定义总是为了我们后续优化计算方便，这一点可以在以后的学习中逐渐体会。</li> <li><mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mo class="mjx-n"><mjx-c c="|"></mjx-c></mjx-mo><mjx-mi class="mjx-i"><mjx-c c="3B8"></mjx-c></mjx-mi><mjx-mo space="3" class="mjx-n"><mjx-c c="22C5"></mjx-c></mjx-mo><mjx-msub space="3"><mjx-mi noIC="true" class="mjx-i"><mjx-c c="x"></mjx-c></mjx-mi><mjx-script style="vertical-align:-0.15em;"><mjx-mi size="s" class="mjx-i"><mjx-c c="b"></mjx-c></mjx-mi></mjx-script></mjx-msub><mjx-mo class="mjx-n"><mjx-c c="|"></mjx-c></mjx-mo></mjx-math></mjx-container> 的大小，决定了我们对预测点属于某一个类别的肯定程度。例如我们从小到大的百分制考试中，以 60 为分界线，离 60 越远的分数，例如 10 分或者 90 分，我们总是能肯定对这一部分知识的掌握越好或者越坏，可以选拔优秀或者淘汰不合格，越靠近 60 的分数，其实可上可下，我们不好做优劣判断，这与逻辑回归是一个道理。</li></ul> <p>将上面的思路，写成数学表达式就是，我们期望找到一个函数，将 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="y"></mjx-c></mjx-mi><mjx-mo space="4" class="mjx-n"><mjx-c c="="></mjx-c></mjx-mo><mjx-mi space="4" class="mjx-i"><mjx-c c="3B8"></mjx-c></mjx-mi><mjx-mo space="3" class="mjx-n"><mjx-c c="22C5"></mjx-c></mjx-mo><mjx-msub space="3"><mjx-mi noIC="true" class="mjx-i"><mjx-c c="x"></mjx-c></mjx-mi><mjx-script style="vertical-align:-0.15em;"><mjx-mi size="s" class="mjx-i"><mjx-c c="b"></mjx-c></mjx-mi></mjx-script></mjx-msub></mjx-math></mjx-container> 送入，得到一个概率，这个概率越趋近于 1 ，则表示判定属于其中一类的概率越大，这个概率越趋近于 0 ，则表示不属于这一类（即属于另一类）的概率越大。区分类别的概率边界值就是 0.5。</p> <p>前辈们已经为我们找到了这个函数，命名为 sigmoid 函数，有的地方又称之为逻辑函数，它的数学表达式如下：</p>
{\rm sigmoid}(t) = \frac{1}{1 + e^{-t}}

<p>于是，我们得到的逻辑回归模型就是这样一个模型：</p>
{\rm sigmoid}(x) = \cfrac{1}{1 + e^{-\theta \cdot x}}

<p>以下对损失函数的推导中，我们总是定义，当 ${\rm sigmoid}(x) &gt;= 0.5 $ 时，类别 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="y"></mjx-c></mjx-mi><mjx-mo space="4" class="mjx-n"><mjx-c c="="></mjx-c></mjx-mo><mjx-mn space="4" class="mjx-n"><mjx-c c="1"></mjx-c></mjx-mn></mjx-math></mjx-container>，当 ${\rm sigmoid}(x) &lt; 0.5 $，类别 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="y"></mjx-c></mjx-mi><mjx-mo space="4" class="mjx-n"><mjx-c c="="></mjx-c></mjx-mo><mjx-mn space="4" class="mjx-n"><mjx-c c="0"></mjx-c></mjx-mn></mjx-math></mjx-container>。</p> <h3 id="广义线性回归"><a href="#广义线性回归" class="header-anchor">#</a> 广义线性回归</h3> <p>逻辑回归是广义的线性回归，预测房价是回归问题，但是否购买房子就是一个分类问题。因此逻辑回归可以看成“线性部分 + 非线性处理”，而“线性部分 + 非线性处理”也是深度学习的神经网络中神经元的表达形式。</p> <p>我是这样理解广义线性回归的：</p> <p>Sigmoid 函数可以用于概率计算：</p>
y = \cfrac{1}{1+e^{-\vec w \cdot \vec x}}

<p>将 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-msup><mjx-mi class="mjx-i"><mjx-c c="e"></mjx-c></mjx-mi><mjx-script style="vertical-align:0.363em;"><mjx-TeXAtom size="s"><mjx-mo class="mjx-n"><mjx-c c="2212"></mjx-c></mjx-mo><mjx-TeXAtom><mjx-mover><mjx-over style="padding-bottom:0.06em;padding-left:0.191em;margin-bottom:-0.516em;"><mjx-mo class="mjx-n"><mjx-c c="20D7"></mjx-c></mjx-mo></mjx-over><mjx-base><mjx-mi class="mjx-i"><mjx-c c="w"></mjx-c></mjx-mi></mjx-base></mjx-mover></mjx-TeXAtom><mjx-mo class="mjx-n"><mjx-c c="22C5"></mjx-c></mjx-mo><mjx-TeXAtom><mjx-mover><mjx-over style="padding-bottom:0.06em;padding-left:0.064em;margin-bottom:-0.516em;"><mjx-mo class="mjx-n"><mjx-c c="20D7"></mjx-c></mjx-mo></mjx-over><mjx-base><mjx-mi class="mjx-i"><mjx-c c="x"></mjx-c></mjx-mi></mjx-base></mjx-mover></mjx-TeXAtom></mjx-TeXAtom></mjx-script></mjx-msup></mjx-math></mjx-container> 写成 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="y"></mjx-c></mjx-mi></mjx-math></mjx-container> 的函数，即</p>
e^{-\vec w \cdot \vec x} = \cfrac{1-y}{y}

<p>两边同时取对数，再乘以 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mo class="mjx-n"><mjx-c c="2212"></mjx-c></mjx-mo><mjx-mn class="mjx-n"><mjx-c c="1"></mjx-c></mjx-mn></mjx-math></mjx-container>，得</p>
\vec w \cdot \vec x = \ln \cfrac{y}{1-y}

<p>因此，对概率 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-i"><mjx-c c="y"></mjx-c></mjx-mi></mjx-math></mjx-container> 做一个非线性变换 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mi class="mjx-n"><mjx-c c="l"></mjx-c><mjx-c c="n"></mjx-c></mjx-mi><mjx-mo class="mjx-n"><mjx-c c="2061"></mjx-c></mjx-mo><mjx-mfrac space="2"><mjx-frac><mjx-num><mjx-nstrut></mjx-nstrut><mjx-mrow size="s"><mjx-mpadded><mjx-block style="margin:0.896em 0 0.313em;"><mjx-mrow></mjx-mrow></mjx-block></mjx-mpadded><mjx-mstyle style="font-size:141.4%;"><mjx-TeXAtom><mjx-mi class="mjx-i"><mjx-c c="y"></mjx-c></mjx-mi></mjx-TeXAtom></mjx-mstyle></mjx-mrow></mjx-num><mjx-dbox><mjx-dtable><mjx-line></mjx-line><mjx-row><mjx-den><mjx-dstrut></mjx-dstrut><mjx-mrow size="s"><mjx-mpadded><mjx-block style="margin:0.896em 0 0.313em;"><mjx-mrow></mjx-mrow></mjx-block></mjx-mpadded><mjx-mstyle style="font-size:141.4%;"><mjx-TeXAtom><mjx-mn class="mjx-n"><mjx-c c="1"></mjx-c></mjx-mn><mjx-mo space="3" class="mjx-n"><mjx-c c="2212"></mjx-c></mjx-mo><mjx-mi space="3" class="mjx-i"><mjx-c c="y"></mjx-c></mjx-mi></mjx-TeXAtom></mjx-mstyle></mjx-mrow></mjx-den></mjx-row></mjx-dtable></mjx-dbox></mjx-frac></mjx-mfrac></mjx-math></mjx-container> ，它就是自变量 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-TeXAtom><mjx-mover><mjx-over style="padding-bottom:0.06em;padding-left:0.064em;margin-bottom:-0.516em;"><mjx-mo class="mjx-n"><mjx-c c="20D7"></mjx-c></mjx-mo></mjx-over><mjx-base><mjx-mi class="mjx-i"><mjx-c c="x"></mjx-c></mjx-mi></mjx-base></mjx-mover></mjx-TeXAtom></mjx-math></mjx-container> 的线性函数，因此是一个回归问题。</p> <h3 id="逻辑回归的损失函数"><a href="#逻辑回归的损失函数" class="header-anchor">#</a> 逻辑回归的损失函数</h3> <p>损失函数具有这样的性质：它度量了预测值和真实值的差别，对于一个样本而言它是非负数，且当预测值与真实值越接近时，损失函数的值越小，当预测值与真实值差别越大时，损失函数的值应该越大。</p> <p>我们需要一个函数，这个函数可以度量概率和损失的关系，负对数函数就是这样一个函数，把概率从 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mo class="mjx-n"><mjx-c c="["></mjx-c></mjx-mo><mjx-mn class="mjx-n"><mjx-c c="0"></mjx-c></mjx-mn><mjx-mo class="mjx-n"><mjx-c c=","></mjx-c></mjx-mo><mjx-mn space="2" class="mjx-n"><mjx-c c="1"></mjx-c></mjx-mn><mjx-mo class="mjx-n"><mjx-c c="]"></mjx-c></mjx-mo></mjx-math></mjx-container> 映射到损失 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mo class="mjx-n"><mjx-c c="["></mjx-c></mjx-mo><mjx-mn class="mjx-n"><mjx-c c="0"></mjx-c></mjx-mn><mjx-mo class="mjx-n"><mjx-c c=","></mjx-c></mjx-mo><mjx-mo space="2" class="mjx-n"><mjx-c c="+"></mjx-c></mjx-mo><mjx-mi class="mjx-n"><mjx-c c="221E"></mjx-c></mjx-mi><mjx-mo class="mjx-n"><mjx-c c="]"></mjx-c></mjx-mo></mjx-math></mjx-container>。因为负对数可以理解为先取倒数再取对数，取导数把 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mo class="mjx-n"><mjx-c c="["></mjx-c></mjx-mo><mjx-mn class="mjx-n"><mjx-c c="0"></mjx-c></mjx-mn><mjx-mo class="mjx-n"><mjx-c c=","></mjx-c></mjx-mo><mjx-mn space="2" class="mjx-n"><mjx-c c="1"></mjx-c></mjx-mn><mjx-mo class="mjx-n"><mjx-c c="]"></mjx-c></mjx-mo></mjx-math></mjx-container> 映射到 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mo class="mjx-n"><mjx-c c="["></mjx-c></mjx-mo><mjx-mn class="mjx-n"><mjx-c c="1"></mjx-c></mjx-mn><mjx-mo class="mjx-n"><mjx-c c=","></mjx-c></mjx-mo><mjx-mo space="2" class="mjx-n"><mjx-c c="+"></mjx-c></mjx-mo><mjx-mi class="mjx-n"><mjx-c c="221E"></mjx-c></mjx-mi><mjx-mo class="mjx-n"><mjx-c c="]"></mjx-c></mjx-mo></mjx-math></mjx-container>，取对数把 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mo class="mjx-n"><mjx-c c="["></mjx-c></mjx-mo><mjx-mn class="mjx-n"><mjx-c c="1"></mjx-c></mjx-mn><mjx-mo class="mjx-n"><mjx-c c=","></mjx-c></mjx-mo><mjx-mo space="2" class="mjx-n"><mjx-c c="+"></mjx-c></mjx-mo><mjx-mi class="mjx-n"><mjx-c c="221E"></mjx-c></mjx-mi><mjx-mo class="mjx-n"><mjx-c c="]"></mjx-c></mjx-mo></mjx-math></mjx-container> 映射到 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mo class="mjx-n"><mjx-c c="["></mjx-c></mjx-mo><mjx-mn class="mjx-n"><mjx-c c="0"></mjx-c></mjx-mn><mjx-mo class="mjx-n"><mjx-c c=","></mjx-c></mjx-mo><mjx-mo space="2" class="mjx-n"><mjx-c c="+"></mjx-c></mjx-mo><mjx-mi class="mjx-n"><mjx-c c="221E"></mjx-c></mjx-mi><mjx-mo class="mjx-n"><mjx-c c="]"></mjx-c></mjx-mo></mjx-math></mjx-container>，而在类标这里起到了指示的作用，因此我们一般设置类标为 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mn class="mjx-n"><mjx-c c="0"></mjx-c></mjx-mn></mjx-math></mjx-container> 和 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mn class="mjx-n"><mjx-c c="1"></mjx-c></mjx-mn></mjx-math></mjx-container>。</p> <p>而上面的描述其实就是<strong>交叉熵损失函数</strong>，交叉熵损失函数计算损失的特点是：损失只由类标的预测概率决定，如果类标所对应的预测概率越大，损失越小，如果类标所对应的预测概率越小，损失越大。</p> <p>而交叉熵损失函数等价于极大似然估计，即交叉熵最小化等价于对数似然极大化。这是我看到的很多介绍逻辑回归的资料上面的两种对目标函数的定义，即：</p> <p>1、目标函数如果是交叉熵：则最小化；
2、目标函数如果是对数似然，则极大化。</p> <p>二者是等价的，它们的解析表示式也仅仅只相差一个负号。</p> <h3 id="交叉熵损失函数梯度公式的推导"><a href="#交叉熵损失函数梯度公式的推导" class="header-anchor">#</a> 交叉熵损失函数梯度公式的推导</h3> <p>二分类问题逻辑回归的损失函数的梯度函数公式的推导我写在这里了：<a href="https://www.jianshu.com/p/b8249e6ee85f" target="_blank" rel="noopener noreferrer">二分类问题逻辑回归的损失函数的梯度函数<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>。下面是手写笔记：</p> <p><img src="http://upload-images.jianshu.io/upload_images/414598-c00719b5ab140f49.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="交叉熵损失函数梯度公式的推导"></p> <h2 id="逻辑回归应用于多分类问题"><a href="#逻辑回归应用于多分类问题" class="header-anchor">#</a> 逻辑回归应用于多分类问题</h2> <p>一般地，二分类问题应用于多分类问题又两种思路：1、一对一；2、一对多。可以看一看 scikit-learn 文档对于“一对一”和“一对多”的描述。</p> <p>1、一对一
<a href="https://scikit-learn.org/stable/modules/multiclass.html#ovo-classification" target="_blank" rel="noopener noreferrer">https://scikit-learn.org/stable/modules/multiclass.html#ovo-classification<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <a href="https://scikit-learn.org/stable/modules/generated/sklearn.multiclass.OneVsOneClassifier.html" target="_blank" rel="noopener noreferrer">https://scikit-learn.org/stable/modules/generated/sklearn.multiclass.OneVsOneClassifier.html<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>
2、一对多
<a href="https://scikit-learn.org/stable/modules/multiclass.html#ovr-classification" target="_blank" rel="noopener noreferrer">https://scikit-learn.org/stable/modules/multiclass.html#ovr-classification<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a> <a href="https://scikit-learn.org/stable/modules/generated/sklearn.multiclass.OneVsRestClassifier.html" target="_blank" rel="noopener noreferrer">https://scikit-learn.org/stable/modules/generated/sklearn.multiclass.OneVsRestClassifier.html<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <p>中文：<a href="http://sklearn.apachecn.org/#/docs/13?id=_112-%E5%A4%9A%E7%B1%BB%E5%92%8C%E5%A4%9A%E6%A0%87%E7%AD%BE%E7%AE%97%E6%B3%95" target="_blank" rel="noopener noreferrer">http://sklearn.apachecn.org/#/docs/13?id=_112-%E5%A4%9A%E7%B1%BB%E5%92%8C%E5%A4%9A%E6%A0%87%E7%AD%BE%E7%AE%97%E6%B3%95<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <p>而逻辑回归应用于多分类问题可以使用更精准的，我认为是特殊的“一对一”的方法：softmax 回归。</p> <h3 id="softmax-回归"><a href="#softmax-回归" class="header-anchor">#</a> softmax 回归</h3> <p>在很多资料上我们会看到 softmax 回归，其实我觉得 softmax 回归和逻辑回归是一回事。逻辑回归的 sigmoid 函数把取值映射成概率，softmax 函数做的也是相同的事情。</p> <p>softmax 函数把取值映射成概率的做法是先取指数函数，目的是把取值映射到 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mo class="mjx-n"><mjx-c c="["></mjx-c></mjx-mo><mjx-mn class="mjx-n"><mjx-c c="0"></mjx-c></mjx-mn><mjx-mo class="mjx-n"><mjx-c c=","></mjx-c></mjx-mo><mjx-mo space="2" class="mjx-n"><mjx-c c="+"></mjx-c></mjx-mo><mjx-mi class="mjx-n"><mjx-c c="221E"></mjx-c></mjx-mi><mjx-mo class="mjx-n"><mjx-c c="]"></mjx-c></mjx-mo></mjx-math></mjx-container>，然后再归一化，因为如果不把取值映射成正数，归一化就无从下手，更不能解释概率是负数的问题了（虽然描述可能不太准确，但我想意思还是能表达清楚）。</p> <p>在深度学习中，如果是二分类问题，输出层使用的激活函数是 sigmoid，而多分类问题，输出层使用的激活函数是 softmax。</p> <h2 id="scikit-learn-的逻辑回归"><a href="#scikit-learn-的逻辑回归" class="header-anchor">#</a> scikit-learn 的逻辑回归</h2> <p>1、scikit-learn 的逻辑回归加上了正则化项，正则化的强度可以由使用者来指定。</p> <p>参数 C 是一个浮点数，默认的值是 <mjx-container jax="CHTML" class="MathJax"><mjx-math class=" MJX-TEX"><mjx-mn class="mjx-n"><mjx-c c="1"></mjx-c><mjx-c c="."></mjx-c><mjx-c c="0"></mjx-c></mjx-mn></mjx-math></mjx-container>。这个 C 是正则化强度的倒数，如果 C 越小，正则化强度越大。</p> <p>2、对于多分类问题，不同的多分类的方法对应了可以使用的不同的训练方法，这一点需要参考文档。</p> <h3 id="最大熵模型"><a href="#最大熵模型" class="header-anchor">#</a> 最大熵模型</h3> <p>逻辑回归其实是最大熵模型的特例，我另外写了学习笔记。</p> <p>（本文完）</p> <h2 id="参考资料"><a href="#参考资料" class="header-anchor">#</a> 参考资料</h2> <p>[1] 李航. 统计学习方法（第 2 版）第 6 章“逻辑回归”. 北京：清华大学出版社，2019.</p> <p>[2] 周志华. 机器学习（第 3 章第 3 节“对数几率回归”）. 北京：清华大学出版社.</p> <hr> <p>以下为草稿，我自己留着备用，读者可以忽略，欢迎大家批评指正。</p> <h3 id="参考资料-2"><a href="#参考资料-2" class="header-anchor">#</a> 参考资料</h3> <p>1、scikit-learn 官方文档：
英文：<a href="https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression" target="_blank" rel="noopener noreferrer">https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>
中文：<a href="http://sklearn.apachecn.org/#/docs/2?id=_1111-logistic-%E5%9B%9E%E5%BD%92" target="_blank" rel="noopener noreferrer">http://sklearn.apachecn.org/#/docs/2?id=_1111-logistic-回归<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <p>2、刘建平的文章：
（1）逻辑回归原理小结
地址：https://www.cnblogs.com/pinard/p/6029432.html
（2）scikit-learn 逻辑回归类库使用小结
地址：https://www.cnblogs.com/pinard/p/6035872.html</p> <p>3、Aurélien，Géron 著：《Sklearn 与 TensorFlow 机器学习实用指南》</p> <p>官方 GitHub 代码仓库：<a href="https://github.com/ageron/handson-ml/blob/master/04_training_linear_models.ipynb" target="_blank" rel="noopener noreferrer">https://github.com/ageron/handson-ml/blob/master/04_training_linear_models.ipynb<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <p>在 nbviewer 上查看：<a href="https://nbviewer.jupyter.org/github/ageron/handson-ml/blob/master/04_training_linear_models.ipynb" target="_blank" rel="noopener noreferrer">https://nbviewer.jupyter.org/github/ageron/handson-ml/blob/master/04_training_linear_models.ipynb<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <p>4、开源组织 ApacheCN 也对这本书做了翻译：ApacheCN
地址：<a href="https://www.bookstack.cn/read/hands_on_Ml_with_Sklearn_and_TF/spilt.6.docs-4.%E8%AE%AD%E7%BB%83%E6%A8%A1%E5%9E%8B.md" target="_blank" rel="noopener noreferrer">https://www.bookstack.cn/read/hands_on_Ml_with_Sklearn_and_TF/spilt.6.docs-4.%E8%AE%AD%E7%BB%83%E6%A8%A1%E5%9E%8B.md<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <p>5、GLM(广义线性模型) 与 LR(逻辑回归) 详解</p> <p>https://blog.csdn.net/Cdd2xd/article/details/75635688</p></div> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">4/10/2021, 6:19:58 PM</span></div></footer> <!----> </main></div><div class="global-ui"><!----></div></div>
    <script src="/book/assets/js/app.a4355b0d.js" defer></script><script src="/book/assets/js/2.ba785ee6.js" defer></script><script src="/book/assets/js/44.386d9aea.js" defer></script>
  </body>
</html>
